package com.jinsi.service.ylt.iml;

import com.jinsi.mapper.ylt.AuditListMapper;
import com.jinsi.pojo.SyUserAudit;
import com.jinsi.pojo.SyUserAuditTurn;
import com.jinsi.service.ylt.AuditListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @ClassName AuditListServiceImpl
 * @Content 申请职位审核列表service接口实现类
 * @Author 姚龙腾
 * @Date 2022-08-06 10:40
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AuditListServiceImpl implements AuditListService {
    @Autowired
    private AuditListMapper auditListMapper;


    /**
     * 获取全部申请职位人员信息
     * @param auditStats
     * @return List<SyUserAudit>
     */
    @Override
    @Transactional(readOnly = true)
    public List<SyUserAudit> getAll(Integer auditStats) {
        return auditListMapper.getAll(auditStats);
    }


    /**
     *
     * 根据输入信息进行模糊查询
     * @param auditStats
     * @param userName
     * @param auditTime
     * @return List<SyUserAudit>
     */
    @Override
    @Transactional(readOnly = true)
    public List<SyUserAudit> getAllByLike(
            Integer auditStats,
            String userName,
            String auditTime) {
        return auditListMapper.getAllByLike(
                auditStats,
                userName,
                auditTime);
    }


    /**
     * 修改申请审核状态
     * 添加审核驳回记录
     * @param auditId
     * @param auditStats
     * @param turn
     */
    @Override
    public void upAudit(Integer auditId, Integer auditStats,SyUserAuditTurn turn){
        auditListMapper.upAudit(auditId, auditStats);
        turn.setTurnTime(new Date());
        auditListMapper.addAuditTurn(turn);
    }


    /**
     * 修改申请审核状态
     * @param auditId
     * @param auditStats
     */
    @Override
    public void upAudit(Integer auditId, Integer auditStats) throws Exception {
        int num = auditListMapper.upAudit(auditId, auditStats);
        if(num == 0){
            throw new Exception();
        }
    }


    /**
     * 添加审核驳回记录
     * @param turn
     * @throws Exception
     */
    @Override
    public void addAuditTurn(SyUserAuditTurn turn) throws Exception {
        int num = auditListMapper.addAuditTurn(turn);
        if (num == 0){
            throw new Exception();
        }
    }
}
